#include <iostream>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

const char *pathname = "/home/ryan/Linux_code/linux/36_sem_test";
const int proj_id = 0x11223344;

key_t getftok()
{
    key_t key = ftok(pathname, proj_id);
    if (key < 0)
    {
        cerr << "ftok error! eoorr:" << errno << " strerror:" << strerror(errno) << endl;
        exit(1);
    }
    return key;
}

int main()
{
    key_t key = getftok();

    //创建信号量集 
    int semid =semget(key, 1, IPC_CREAT | IPC_EXCL);

    sleep(20);
    //删除信号量集
    semctl(semid,0,IPC_RMID);
}
